<?php
namespace Seller\Model;
class GoodsModel extends BaseModel{
    
    protected $tableName = 'goods';
    
    //自动认证
    protected $_validate = array(
        array( 'customer_id' , 'require' , '非法信息'),
        array('name','require','商品名称不能为空！'),
        array('earn13','','en13码已存在，请核对编码！',0,'unique',1),
        array('goods_type_id','/^[0-9]+$/','请选择商品分类'),
        array('goods_brand_id','/^[0-9]+$/','请选择品牌'), 
        array('pic_thumb','require','商品首图必须上传'),
        array('pic_list','require','商品列表图片不能为空'),
        array('weight','require','产品重量不能为空')
    );
    
    //产品列表
    public function getList($where = array() , $row , $order = array('g.id'=>"DESC")) {
        //开始分页信息
        $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $count = $this->alias('g')->where($where)->count();
        //分页
        $pagesize = $row; #每页数量
        $offset = $pagesize * ($p - 1); //计算记录偏移量
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $limit = $offset . ',' . $pagesize;
        $list = $this
                ->join('as g LEFT JOIN zt_goods_type as gt ON g.goods_type_id = gt.id')
                ->join('LEFT JOIN zt_goods_brand as gb ON g.goods_brand_id = gb.id')
                ->join('LEFT JOIN zt_partner as p ON g.own_shopid = p.id')
                ->where($where)->order($order)->limit($limit)
                ->field('g.*,gt.name as type_name,gb.name as brand_name,p.name as partner_name')
				->order('g.heat_num DESC') //根据热度值排序
                ->select();
        $arr = array('count' => $count, 'list' => $list, 'page' => $page,);
        return $arr;
    }
}